package com.example.demo.controller;

import com.example.demo.netty.TextWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("socket")

public class TestController {

    @Autowired
    TextWebSocketHandler textWebSocketHandler;

    @GetMapping("test.do")
    public Object test(@RequestParam String receiverUuid, @RequestParam String msg) {
        if (StringUtils.isEmpty(receiverUuid)) {
            textWebSocketHandler.broadcast(msg);
        } else {
            textWebSocketHandler.sendMessage(receiverUuid, msg);
        }
        return true;
    }

    @GetMapping("test2.do")
    public Object test2(@RequestParam String msg) {

        textWebSocketHandler.broadcast(msg);
        return true;
    }
}
